<template>
  <div>
    <div class="table">
      <el-table
        :data="table.data"
        :loading="table.loading"
        style="width: 100%"
        :header-cell-style="{
          background: '#F1F1F1',
          'font-size': '14px',
          'font-weight': 600,
          color: '#333333',
        }"
        :cell-style="{
          'font-size': '14px',
          'font-weight': 400,
          color: '#333333',
        }"
      >
        <el-table-column label="序号">
          <template #default="scope">
            {{ (scope.$index + 1).toString().padStart(2, "0") }}
          </template>
        </el-table-column>
        <el-table-column prop="optTime" label="修改时间" width="200" />
        <el-table-column prop="optUser" label="修改人" />
        <el-table-column prop="optDesc" label="修改内容" width="500" />
        <template #empty>
          <el-empty :image="imgNone" />
        </template>
      </el-table>
    </div>
    <div class="pagination">
      <el-pagination
        v-model:current-page="pagination.currentPage"
        v-model:page-size="pagination.pageSize"
        :page-sizes="pagination.pageSizes"
        layout="total,sizes, prev, pager, next, jumper"
        :total="table.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script setup>
import { reactive, ref } from "vue";
import { getJournal } from "../request.js";

const props = defineProps({
  operationId: String,
});

// 表格
const table = reactive({
  data: [{}],
  total: 0,
  loading: true,
});

const pagination = reactive({
  currentPage: 1,
  pageSize: 5,
  pageSizes: [5, 10, 15, 20],
});

const getData = async () => {
  await getJournal({
    userId: props.operationId.userId,
    pageNo: pagination.currentPage,
    pageSize: pagination.pageSize,
  }).then((res) => {
    console.log("res ===>", res);
    table.data = res.data.result.items;
    table.total = parseInt(res.data.result.total);
    table.loading = false;
  });
};

const handleCurrentChange = (value) => {
  pagination.currentPage = value;
  getData();
};

const handleSizeChange = (value) => {
  pagination.pageSize = value;
  getData();
};

getData();
</script>

<style lang="less" scoped>
.table {
  margin-bottom: 15px;
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
</style>